<?php
$conn = new mysqli("rm-2ze1kg3ip763wer90o.mysql.rds.aliyuncs.com","liweixuan","12345678","test",3306);
if($conn->connect_error){
  echo 0;
  exit();
}

//查看SQL文件是否存在
$sqlPath = BASE_PATH."/install/sql/test.sql";

if(!file_exists($sqlPath)){
  $response->responseData(false,"没有找到安装数据表的相关文件信息");
}

//创建数据库
$conn->query("drop database test2");
$conn->query("create database test2");

//设置编码
$conn->query("SET NAMES 'UTF8'");

//选择相应库
$conn->query("USE test2");

//获取要执行SQL文件的内容
$createTableSqlText = file_get_contents($sqlPath);

$sqlArr = explode(";",$createTableSqlText);

$sqlCount = count($sqlArr) - 1;

$successCount = 0;

//关闭事物自动提交
$db->mysqlDB->falseAutoCommit();

//去除空项
for($i=0;$i<count($sqlArr);$i++){

  $sql = $sqlArr[$i];

  if(strlen(trim($sql)) != 0){
    $rs = $conn->query($sql);
    if($rs){
      $successCount++;
    }
  }
}



if($sqlCount == $successCount){
  $db->mysqlDB->actionCommint();
  $db->mysqlDB->trueAutoCommit();
  $response->responseData(true,"安装完成");
}else{
  $db->mysqlDB->rollBackCommint();
  $db->mysqlDB->trueAutoCommit();
  $response->responseData(false,"抱歉，安装失败，请重新尝试");
}


?>